package com.wkbb.sports.model;

import com.alibaba.fastjson.JSON;
import com.wkbb.common.dto.basic.StudentInfoDto;
import com.wkbb.common.dto.basic.UserDto;
import com.wkbb.common.enums.SexTypeEnum;
import com.wkbb.sports.dto.HifeWorkDto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.beanutils.BeanUtils;

import java.util.Date;

/**
 * @author lbh
 * @date 2021年03月29日 17:58:34
 * @description: hlife_work_rule  作业要求表
 */
@Data
public class HlifeWorkRule extends BaseEntity{

    @ApiModelProperty(value = "项目类型(1体检 2体质)")
    private Integer projectType;

    @ApiModelProperty(value = "学校ID")
    private Long orgId;

    @ApiModelProperty(value = "评分标准ID")
    private Long projectRuleId;

    @ApiModelProperty(value = "教师ID")
    private Long teacherId;

    @ApiModelProperty(value = "模式(1模拟考试 2限时限数 3数量模式 4时间模式)")
    private Integer modelType;

    @ApiModelProperty(value = "性别(1男 2女3不限4区分男女)")
    private Byte sex;

    @ApiModelProperty(value = "分数")
    private String score;
    @ApiModelProperty(value = "跳绳类型")
    private String jumpType;

    @ApiModelProperty(value = "轮数")
    private Integer times;

    @ApiModelProperty(value = "次数")
    private Integer number;

    @ApiModelProperty(value = "区分男女时男生次数")
    private Integer boyNumber;

    @ApiModelProperty(value = "区分男女时女生次数")
    private Integer girlNumber;

    @ApiModelProperty(value = "时长")
    private Integer duration;

    @ApiModelProperty(value = "区分男女时男生时长")
    private Integer boyDuration;

    @ApiModelProperty(value = "区分男女时女生时长")
    private Integer girlDuration;

    @ApiModelProperty(value = "单位(1千克/米²,2毫升,3分·秒,4秒,5米,6厘米,7次)")
    private Integer unit;

    public static HlifeWork generateHifeWork1(HifeWorkDto hifeWorkDto){
        HlifeWork hifeWork=new HlifeWork();
        hifeWork.setProjectId(hifeWorkDto.getProjectId());
        hifeWork.setProjectName(hifeWorkDto.getProjectName());
        hifeWork.setOrgId(hifeWorkDto.getOrgId());
        hifeWork.setGradeId(hifeWorkDto.getGradeId());
        hifeWork.setGradeName(hifeWorkDto.getGradeName());
        hifeWork.setClassId(hifeWorkDto.getClassId());
        hifeWork.setClassName(hifeWorkDto.getClassName());
        hifeWork.setTeacherId(hifeWorkDto.getTeacherId());
        hifeWork.setBeginTime(hifeWorkDto.getBeginTime());
        hifeWork.setEndTime(hifeWorkDto.getEndTime());
        hifeWork.setStatus(0);
        hifeWork.setRemark(hifeWorkDto.getRemark());
        hifeWork.setFaceRecognition(hifeWorkDto.getFaceRecognition());

        //hifeWork.setCreateBy("创建人");
        hifeWork.setCreateTime(new Date());
//        hifeWork.setUpdateBy("修改人");
//        hifeWork.setUpdateTime(new Date());
        return hifeWork;
    }

    public static HlifeWork generateHifeWork(){
        HlifeWork hifeWork=new HlifeWork();
        hifeWork.setProjectId((byte) 1);
        hifeWork.setProjectName("项目名称");
        hifeWork.setOrgId(1L);
        hifeWork.setGradeId(1L);
        hifeWork.setGradeName("年级名称");
        hifeWork.setClassId(1L);
        hifeWork.setClassName("班级名称");
        hifeWork.setTeacherId(1L);
        hifeWork.setBeginTime(new Date());
        hifeWork.setEndTime(new Date());
        hifeWork.setRuleId(1L);
        hifeWork.setStatus(1);
        hifeWork.setRemark("备注");

        hifeWork.setCreateBy("创建人");
        hifeWork.setCreateTime(new Date());
//        hifeWork.setUpdateBy("修改人");
//        hifeWork.setUpdateTime(new Date());
        return hifeWork;
    }

    //初始化hlife_work_student  作业记录表
    public static HlifeWorkStudent generateHifeWorkStudentFromWork(HlifeWork hifeWorkDto, HlifeUser hlifeUser, UserDto userDto){
        HlifeWorkStudent hlifeWorkStudent=new HlifeWorkStudent();
        hlifeWorkStudent.setOrgId(hifeWorkDto.getOrgId());
        hlifeWorkStudent.setProjectId(hifeWorkDto.getProjectId());
        hlifeWorkStudent.setWorkId(hifeWorkDto.getId());
        hlifeWorkStudent.setGradeId(hifeWorkDto.getGradeId());
        hlifeWorkStudent.setGradeName(hifeWorkDto.getGradeName());
        hlifeWorkStudent.setClassId(hifeWorkDto.getClassId());
        hlifeWorkStudent.setClassName(hifeWorkDto.getClassName());

        hlifeWorkStudent.setStudentId(hlifeUser.getUserId());
        hlifeWorkStudent.setSex(hlifeUser.getSex());
        hlifeWorkStudent.setStudentName(hlifeUser.getUserName());
        hlifeWorkStudent.setUserNo(hlifeUser.getUserNo());
        hlifeWorkStudent.setHeadImgUrl(hlifeUser.getHeadImg());

        hlifeWorkStudent.setScore(0.0);
        hlifeWorkStudent.setAchivement(0.0);
        hlifeWorkStudent.setPlusesScore(0.0);
        hlifeWorkStudent.setReached(0);

        hlifeWorkStudent.setActualTime(0);
        hlifeWorkStudent.setStatus(hifeWorkDto.getStatus());
        hlifeWorkStudent.setCreateBy(userDto.getName());
        hlifeWorkStudent.setCreateTime(new Date());
        return hlifeWorkStudent;
    }

    //初始化hlife_work_student  作业记录表
    public static HlifeWorkStudent generateHifeWorkStudentFromWork(HlifeWork hifeWorkDto, StudentInfoDto hlifeUser, UserDto userDto){
        HlifeWorkStudent hlifeWorkStudent=new HlifeWorkStudent();
        hlifeWorkStudent.setOrgId(hifeWorkDto.getOrgId());
        hlifeWorkStudent.setProjectId(hifeWorkDto.getProjectId());
        hlifeWorkStudent.setWorkId(hifeWorkDto.getId());
        hlifeWorkStudent.setGradeId(hifeWorkDto.getGradeId());
        hlifeWorkStudent.setGradeName(hifeWorkDto.getGradeName());
        hlifeWorkStudent.setClassId(hifeWorkDto.getClassId());
        hlifeWorkStudent.setClassName(hifeWorkDto.getClassName());

        hlifeWorkStudent.setStudentId(hlifeUser.getUserId());
        Integer sex = (hlifeUser.getSex().equals(SexTypeEnum.MAN.getDesc())) ? SexTypeEnum.MAN.getValue() : SexTypeEnum.WOMAN.getValue();
        hlifeWorkStudent.setSex(sex.byteValue());
        hlifeWorkStudent.setStudentName(hlifeUser.getName());
        hlifeWorkStudent.setUserNo(hlifeUser.getStudentNo());
        hlifeWorkStudent.setHeadImgUrl(hlifeUser.getHeadImgUrl());

        hlifeWorkStudent.setScore(0.0);
        hlifeWorkStudent.setAchivement(0.0);
        hlifeWorkStudent.setPlusesScore(0.0);
        hlifeWorkStudent.setReached(0);

        hlifeWorkStudent.setActualTime(0);
        hlifeWorkStudent.setStatus(hifeWorkDto.getStatus());
        hlifeWorkStudent.setCreateBy(userDto.getName());
        hlifeWorkStudent.setCreateTime(new Date());
        return hlifeWorkStudent;
    }

    public String getIntro() {
        String str = "";
        switch (modelType){
            case 2:
                if (sex == 3){
                    str = duration+"分钟"+number+"次";
                }else{
                    str = "男："+boyDuration+"分钟"+boyNumber+"次 女："+girlDuration+"分钟"+girlNumber+"次";
                }
                break;
            case 3:
                if (sex == 3){
                    str = number+"次";
                }else{
                    str = "男："+boyNumber+"次 女："+girlNumber+"次";
                }
                break;
            case 4:
                if (sex == 3){
                    str = duration+"分钟";
                }else{
                    str = "男："+boyDuration+"分钟 女："+girlDuration+"分钟";
                }
                break;
        }
        return str;
    }
}
